package com.inspectortime.webapp.inspector.scheduleRule;

import org.springframework.validation.Errors;

import com.inspectortime.domain.ScheduleRule;
import com.inspectortime.domain.type.FrequencyType;

public class RecurringScheduleRuleValidator extends ScheduleRuleValidator {
	
	public void validate(Object obj, Errors errors) {
		ScheduleRule scheduleRule = (ScheduleRule) obj;
	
		//This shouldn't happen, but better to be safe
		if (scheduleRule.getFrequencyType() != FrequencyType.DAY_OF_WEEK) {
			errors.reject("addEditScheduleRule.invalid.data");	
		}
		
		int[] ruleUnits = scheduleRule.getUnits();
		if (ruleUnits == null || ruleUnits.length == 0) {
			errors.rejectValue("units", "addEditScheduleRule.daysOfWeek.required");
		}
		
		super.validate(obj, errors);
		
	}

}
